#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H

#include <vector>
#include "inputtype.h"
#include "inputcallback.h"
#include <utilities/utilities-thread.h>
#include <utilities/utilities-mutex.h>

class InputManager : public Utilities::Thread
{
public:
  static InputManager& inputManager(unsigned int inputsRequested);
  virtual ~InputManager();

  unsigned int numInputs() const;
  void print() const;
  std::string name(unsigned int input) const;
  InputData data(unsigned int input) const;
  void registerCallback(InputCallback* callback);
  void deregisterCallback(InputCallback* callback);

protected:
  virtual void run();

private:
  InputManager(InputManager const&); //never to be implemented
  void operator=(InputManager const&); //never to be implemented

  InputManager(unsigned int inputsRequested, unsigned int pollFrequency=30);
  void poll();
  void checkEvents(unsigned int input);
  void axisEvent(unsigned int input, unsigned int axis, int value);
  void buttonEvent(unsigned int input, unsigned int button, bool value);

  typedef std::vector<InputType*> InputVector;
  typedef std::list<InputCallback*> CallbackList;

  InputType* newInput();

  unsigned int mSleepTime;
  InputVector mInputs;
  mutable Utilities::Mutex mInputMutex;
  CallbackList mCallbacks;
  Utilities::Mutex mCallbackMutex;
};

#endif
